<?php
$this->freshSession();
$pMerBillNo=$rechargeId=$this->getRechId();
$bankid=$_REQUEST["payId"];
$bankid="WXZF";
$uid=$this->user['uid'];
$pAmount=$amount=floatval($_REQUEST['amount']);
$time=date('Y-m-d H:i:s', time());
if($this->update("INSERT INTO {$this->prename}order (order_number, username, recharge_amount, state, time) VALUES('{$rechargeId}', '{$uid}', '{$amount}', '0', '{$time}')")){
		$uid=$this->user['uid'];
}
else{
	echo '操作错误';
	exit;
}
   $notifyUrl="http://www.ba88.vip/userrech/payCallBack.do"; 
	$data = array(
	
	    'channel_no' =>"01",
	    'out_trade_no' =>$rechargeId,    //订单号		
        'channel' =>$bankid,   //支付方式
		'goods_name' =>"123",   //订单说明
		'remark' =>$notifyUrl,  
		'notify_url' =>$notifyUrl,  //回调地址
		'sign' =>$notifyUrl, 
		'amount' =>$amount,   //订单金额	 
	    'merchant_no' =>"10000001",  //商户id  
        'version' => "v1"  
        );
    $data['sign']=$sign=md5($data["channel_no"].$data["out_trade_no"].$data["channel"].$data["goods_name"].$data["remark"].$data["notify_url"].$data["amount"].$data["merchant_no"].$data["version"]); 
    $r=getHttpContent("http://47.100.170.103:81/payapi/gatewap","POST",$data);
    $data = json_decode( $r , 1 );
	$str = $data['payUrlcode'];
    echo $data;

	//$url='?channel_no=01&out_trade_no='.$rechargeId.'&channel='.$bankid.'&sign='.$sign.'&merchant_no=10000001&version=v1&goods_name=123&remark='.$notifyUrl.'&notify_url='.$notifyUrl.'&Amount='.$amount;
	//header("Location: http://47.100.170.103:81/payapi/gatewap".$url);



    
function getHttpContent($url, $method = 'GET', $postData = array())  {  
    $data = '';  
    $user_agent = $_SERVER ['HTTP_USER_AGENT'];
    $header = array (
                "User-Agent: $user_agent" 
    );
    if (!empty($url)) {  
        try {
            $ch = curl_init();  
            curl_setopt($ch, CURLOPT_URL, $url);  
            curl_setopt($ch, CURLOPT_HEADER, false);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
            curl_setopt($ch, CURLOPT_TIMEOUT, 30); //30??3?ê±  
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
            curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header ); 
            //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);  
            if (strtoupper($method) == 'POST') {  
                $curlPost = is_array($postData) ? http_build_query($postData) : $postData;  
                curl_setopt($ch, CURLOPT_POST, 1);  
                curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);  
            }  
            $data = curl_exec($ch);  
            curl_close($ch);  
        } catch (Exception $e) {  
            $data = '';  
        }  
    }  
    return $data;  
}
function xmlToArray($xml){ 
 
         //禁止引用外部xml实体 
         
        libxml_disable_entity_loader(true); 
         
        $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); 
         
        $val = json_decode(json_encode($xmlstring),true); 
         
        return $val; 
     
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title><?php echo $bankid == "wxsm" ? "微信扫码支付" : "支付宝扫码支付";?></title>
<link href="http://www.ba88.vip/source/style-05.css" rel="stylesheet" />
<link href="http://www.ba88.vip/source/new.css?v=1.0" rel="stylesheet" />
	<script language="javascript" type="text/javascript" src="/skin/js/jquery-1.7.2.min.js"></script>
	<script language="javascript" type="text/javascript">
	var timer = null;
	function getOrderStatus(){
		$.ajax({async:false, url:"/index.php/User/orderStatus?rechargeId=<?php echo $merBillNo?>", success: function(data,textStatus,jqXHR){
				if(textStatus == 'success'){
					if(parseInt(data) == 2){
						clearTimeout(timer);
						alert('您已成功支付');
						window.close();
					}else{
						clearTimeout(timer);
						timer = setTimeout("getOrderStatus()", 1000);
					}
				}
			}	
		});
	}
	$(document).ready(function(){
		timer = setTimeout("getOrderStatus()", 1000);
	});
	</script>

</head>

<body>
<?php  
header('content-type:text/html;charset=utf8'); 
?>    
	<div class="divhead">
        <div class="divtitle">
            <img src="<?php echo $bankid == "wxsm" ? "http://www.ba88.vip/images/zfb.jpg" : "http://www.ba88.vip/images/zfb1.jpg" ?>" />
        </div>
    </div>
    <div class="divbody">
        <div class="divcontentleft">
            订单提交成功，请您尽快付款！
        </div>
        <div class="divcontentright">
            应付金额：<font color="red"><?php echo $pAmount;?>元</font>
        </div>
        <div class="divcontent2" style="display:none;">
            请您在提交订单后尽快完成支付，否则订单会自动取消
        </div>
        <div class="divcontent3">
            <div class="divcontent3_left">订单号<?php echo $pMerBillNo?></div><a style="display:none;" href="mqqwpa://im/chat?chat_type=wpa&uin=3495754255&version=1" target="_blank"><img src="<?php echo $str?>" ></a>
        </div>
        <div class="divCode">
            <img id="imgCode" src="<?php echo $str?>"/>
        </div>
        <div class="divdesc">
            请使用微信“扫一扫”扫描二维码以完成支付
        </div>
    </div>
    <div class="divfoot" style="display:none;">
        <div class="divversion">
            支付网关版权所有 2012-2017
        </div>
    </div>	

</body>
</html>				
								
